package com.abel.bigwater.data.sanchuan

import com.abel.bigwater.data.BcdString
import com.alibaba.fastjson.JSON
import io.netty.buffer.Unpooled
import org.junit.Test
import org.slf4j.LoggerFactory

class SanchuanPacketTest {
    @Test
    fun testParse() {
        val fmt = """68 00 9f 68 10 02 18 02 01 11 07 18 06 36 98 00 00 00 3b 11 04 04 60 04 01 97 80 19 02 02 00 f7
76 3c 20 20 04 09 02 00 00 01 a9 00 00 01 a9 00 00 01 a9 00 00 01 a9 00 00 01 a9 00 00 01 a9 00
00 01 a9 00 00 01 a9 00 00 01 a9 00 00 01 a9 00 00 01 a9 00 00 01 a9 00 00 01 a9 00 00 01 a9 00
00 01 a9 00 00 01 a9 00 00 01 a9 00 00 01 a9 00 00 01 a9 00 00 01 3f 00 f5 7b ac 00 f5 bf 5e 00
f5 fb b8 00 f6 34 84 00 f6 4f aa 00 f6 6a bc 00 f6 8c 7c 00 f6 c0 fc 00 f6 ec 76 00 f7 21 6e 00
f7 61 38 a1 16 
"""
        val buf = Unpooled.wrappedBuffer(BcdString.toByteArray(fmt))
        val p = SanchuanPacket.parseBuffer(buf)
        lgr.info("parsed buffer: {}", JSON.toJSONString(p, true))
    }

    @Test
    fun testParseOkay() {
        val fmt = """
            68 00 a1 68 10 05 18 99 00 11 07 18 06 36 60 00 00 00 7f 15 03 04 60 04 03 67 20 32 42 02 00 34
5c 60 fa 00 20 20 04 15 02 00 25 9e 32 00 26 34 46 00 26 8e e6 00 26 bd 76 00 26 e2 d8 00 27 1c
8a 00 27 a8 da 00 28 3f 7a 00 28 d8 04 00 29 7e 1c 00 2a 10 ac 00 2a c4 d4 00 2b 5e 6c 00 2c 06
e6 00 2c 97 be 00 2d 1b da 00 2d 83 22 00 2d 93 8a 00 2d d6 6a 00 2e 19 fe 00 2e 71 b0 00 2e e4
b0 00 2f 4e dc 00 2f e3 ec 00 30 89 00 00 31 26 3a 00 31 c0 cc 00 32 5d fc 00 32 f4 ba 00 33 89
52 00 34 1c 1e d8 16 

"""
        val buf = Unpooled.wrappedBuffer(BcdString.toByteArray(fmt))
        val p = SanchuanPacket.parseBuffer(buf)
        lgr.info("parsed buffer: {}", JSON.toJSONString(p, true))
    }

    @Test
    fun testParseInvalidDate() {
        val fmt = """
            68 00 a1 68 10 05 18 99 00 11 07 18 06 36 60 00 00 00 7f 15 03 04 60 04 03 67 20 32 42 02 00 34
5c 60 21 00 12 20 04 15 02 00 25 9e 32 00 26 34 46 00 26 8e e6 00 26 bd 76 00 26 e2 d8 00 27 1c
8a 00 27 a8 da 00 28 3f 7a 00 28 d8 04 00 29 7e 1c 00 2a 10 ac 00 2a c4 d4 00 2b 5e 6c 00 2c 06
e6 00 2c 97 be 00 2d 1b da 00 2d 83 22 00 2d 93 8a 00 2d d6 6a 00 2e 19 fe 00 2e 71 b0 00 2e e4
b0 00 2f 4e dc 00 2f e3 ec 00 30 89 00 00 31 26 3a 00 31 c0 cc 00 32 5d fc 00 32 f4 ba 00 33 89
52 00 34 1c 1e d8 16 

"""
        val buf = Unpooled.wrappedBuffer(BcdString.toByteArray(fmt))
        val p = SanchuanPacket.parseBuffer(buf)
        lgr.info("parsed buffer: {}", JSON.toJSONString(p, true))
    }

    companion object {
        private val lgr = LoggerFactory.getLogger(SanchuanPacket::class.java)
    }
}